#ifndef ____________WEATHER_____________________
#define  ____________WEATHER_____________________

uniform half _WeatherType;

uniform half4 _WeatherParams;
uniform half4 _WeatherParams2;
uniform half4 _SnowColor;
//uniform half _SnowProcessScale;
uniform half4 _WeatherCtrl;
sampler2D _WeatherTex;
//half4 rbump = tex2D(_WeatherTex, TRANSFORM_TEX(i.uv, _MainTex));
void RainNormalTransform2( float3 worldPos,inout float3 worldNormal )
{
 
	if(_WeatherType==0)
	{
		float2 w2uv0 = float2(worldPos.x  , worldPos.z) *0.3 ;
		half3 rbump = tex2D(_WeatherTex, w2uv0).xyz*2-1;
		worldNormal.xyz = lerp(worldNormal.xyz,rbump.xzy,_WeatherParams2.z*_WeatherCtrl.z* max(0,worldNormal.y));
	}
	 

}
 

#if defined(  GLOBAL_WEATHER )  
	
 
	#define WEATHER_SHINESS( shiness ) if(_WeatherType==0) {  shiness = lerp(shiness,1.0, _WeatherParams.w*_WeatherParams2.z*_WeatherCtrl.z);};  
	 
	#define WEATHER_SHINESS_PBR( SP ) if(_WeatherType==0){SP *= 1.0+ _WeatherParams2.z*_WeatherCtrl.z;};
	#define WEATHER_NORMAL(worldPos,worldNormal ) RainNormalTransform2(   worldPos,  worldNormal ) ;
	#if defined( _ISMETALLIC_ALPHA )   ||defined(   _ISMETALLIC_ON ) || defined(    _ISMETALLIC_GLOSSINALPHA)
		#define WEATHER_GLOSS(gloss)   gloss = lerp(gloss,(1.0-_WeatherParams2.w),0.75*_WeatherParams2.z*_WeatherCtrl.z);;
	#else
		#define WEATHER_GLOSS(gloss)  gloss = lerp(gloss,_WeatherParams2.w,0.75*_WeatherParams2.z*_WeatherCtrl.z);  
	#endif

	void weatherColor(float3 worldPos, float3 worldNormal,inout float3 color , inout float metal )
	{
		if(_WeatherType==1){  
			float2 w2uv0 = float2(worldPos.x  , worldPos.z)   ; 
			half3 snowTex = tex2D(_WeatherTex, w2uv0).xyz ; 
			half _weatherUp = worldNormal.y - snowTex.x* 0.05 ; 
			half _snowT =  step( 1.01-_WeatherParams.z * _WeatherCtrl.x -_WeatherCtrl.y  , _weatherUp ); 
			metal = lerp(_snowT,0,_snowT ); 
			color.rgb = lerp(color.rgb,_SnowColor.rgb,_snowT);
			 
		};
	}
	#define WEATHER_COLOR(worldPos, worldNormal,color , metal )  weatherColor(worldPos, worldNormal,color , metal );
 
#else
	#define WEATHER_SHINESS_PBR( SP ) 
	#define WEATHER_NORMAL(worldPos,worldNormal )  
	#define WEATHER_GLOSS(gloss)   
 
	#define WEATHER_SHINESS( shiness   )  ;

	 #define WEATHER_COLOR(worldPos, worldNormal,color , metal )  ;

	//#define WEATHER_FINAL( color )
	//#define EFFECT_WEATHER_FINAL( color ) 
#endif
 

#endif